<template>
    <div class="main">
        <form>
          <div class="init-form">
            <label>专家姓名: </label>
            <input class="input-class" placeholder="请输入" />
          </div>
          <div class="init-form">
            <label>职称: </label>
            <input class="input-class" placeholder="请输入" />
          </div>
          <div class="init-form">
            <label>号别: </label>

            <select class="input-class" name="public-choice" v-model="typeSelected" @change="getTypeSelected">
              <option :value="type.id" v-for="type in typeList" >{{type.name}}</option>
            </select>

          </div>
          <div class="init-form">
            <label>专家照片: </label>
            <div class="pic-form" @click="selectImg()">
            <input type="file"  id="filed" hidden="" @change="filePreview">
            <p  >
              <span class="pic-text" v-if="textHide">#添加图片</span>
              <img class="pic"  :src="src" />
            </p>
            </div>
          </div>
          <div class="init-form">
            <label>擅长治疗: </label>
            <textarea class="input-class textarea-class"  placeholder="请输入"></textarea>
          </div>
          <div class="init-form-btn">
              <button style="background-color: white; color: #7d7d7d" @click="cancel">取消</button>
              <button style="background-color: #D60000; color: white" @click="save">保存</button>
          </div>
        </form>


    </div>
</template>

<script>
    export default {
        name: "AddDoctor",
        data() {
            return{
                typeList:[
                    {
                        id: '1',
                        name: '普通号'
                    },
                    {
                        id: '2',
                        name: '专家号'
                    },
                    {
                        id: '3',
                        name: '适宜技术号'
                    }
                ],
                typeSelected: '',
                src:'',
                textHide:true,
            }
        },
        methods:{
          cancel: function () {
              this.$router.push({name:'ServiceTeam'});
          },
          save:   function () {
            },
            getTypeSelected(){
                //获取选中的优惠券
                console.log(this.typeSelected);
            },
            selectImg:function(){
                document.getElementById('filed').click();
            },
            filePreview(e){
                let _this = this
                var files = e.target.files[0]
                if (!e || !window.FileReader) return  // 判断是否支持FileReader
                let reader = new FileReader()
                reader.readAsDataURL(files) // 文件转换
                reader.onloadend = function () {
                    _this.src = this.result
                    _this.textHide=false;

                }
            }
        },
        created(){
            this.typeSelected = this.typeList[0].id;
        },
    }
</script>

<style scoped>

  .main{
    margin-top: 1em;
    margin-left: 15em;
    display: flex;
    flex-direction: column;
  }

  .init-form{
   margin-top: 1.5em;
  }

  label{
    /*右对齐*/
    display: inline-block;
    float: left;
    width: 6em;
    text-align: right;
  }

  .input-class{
    width: 250px;
    height: 30px;
    line-height: 1.3;
    border-width: 1px;
    border-style: solid;
    background-color: #fff;
    color: rgba(0, 0, 0, .85);
    border-radius: 2px;
    border-color: #c4c5c7;
    outline: none;
    padding-left: 10px;
    padding-top: 3px;
    margin-left: 1em;
  }

  .textarea-class{
    resize: none;
    width: 40%;
    height: 5em;
  }

  .init-form-btn{
    margin-top: 2em;
    margin-left: 10em;
  }

  .init-form-btn > button{
    width: 10%;
    height: 35px;
    margin-left: 20px;
    border-radius: 5px;
    border-width: 1px;
    border-style: solid;
    border-color: #c4c5c7;
    cursor: pointer;
  }

  .pic-form{
    border-width: 1px;
    border-style: solid;
    border-radius: 2px;
    border-color: #c4c5c7;
    width: 10em;
    height: 10em;
    margin-left: 7em;
    cursor: pointer;
  }

  .pic{
    width: 100%;
  }

  .pic-text{
    font-size: x-small;
    margin-left: 5em;
    color: #D60000;
  }

</style>
